package com.pan.crawler.impl3;

import com.pan.crawler.Search;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;

import java.time.Duration;

public class SearchImpl3 implements Search {

    private final String searchUrl = "http://www.dawensk.com/search.php";

    private EdgeDriver edgeDriver;

    public SearchImpl3(){
        edgeDriver = new EdgeDriver();
        try {
            edgeDriver.navigate().to(searchUrl);
            edgeDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
            WebElement search = edgeDriver.findElement(By.id("key"));
        }catch (Exception e){
            edgeDriver.quit();
            throw new RuntimeException("www.dawensk.com: 网站挂了");
        }
    }

    @Override
    public void find(String content) {
        WebElement key = edgeDriver.findElement(By.id("key"));
        key.sendKeys(content);
        key.submit();
    }

    @Override
    public void close() {
        edgeDriver.quit();
    }

//1.这个网站要传入目录那个网站才能爬
    public static void main(String[] args) {
        new SearchImpl3().find("斗罗");

    }
}
